package com.bonc.ioc.demo.base.error;


import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

/**
 * @ClassName: McpErrorConfig
 * @Author: Liyy
 * @Description: 用户处理HTTP请求异常的拦击
 * @Date: 2019-07-12 10:50:52
 **/
@Configuration
public class McpErrorConfig implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {

    @Override
    public void customize(ConfigurableServletWebServerFactory factory) {
        // 处理401错误,没有被授权
        ErrorPage page401 = new ErrorPage(HttpStatus.UNAUTHORIZED, "/error/unAuthorized");
        //处理404错误
        ErrorPage page404 = new ErrorPage(HttpStatus.NOT_FOUND, "/error/notFind");
        //请求方式不被允许
        ErrorPage page405 = new ErrorPage(HttpStatus.METHOD_NOT_ALLOWED ,"/error/methodNotAllowed");
        //请求超时
        ErrorPage page408 = new ErrorPage(HttpStatus.REQUEST_TIMEOUT ,"/error/requestTimeOut");
        //请求超时
        ErrorPage page413 = new ErrorPage(HttpStatus.PAYLOAD_TOO_LARGE ,"/error/payloadTooLarge");
        factory.addErrorPages(page401,page404,page405,page408,page413);

    }
}
